package com.cwj.film.controller;

import com.cwj.common.domain.film;
import com.cwj.common.utils.utils;
import com.cwj.common.vo.Result;
import com.cwj.common.vo.film.aboutSo;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/about")
public class aboutController {

    @Resource
    private com.cwj.film.service.inter.about about;
    @Resource
    private HttpServletRequest request;
    @PostMapping("/GetFilmByTitleType")
    private Result GetFilmByTitleType(aboutSo aboutSo) throws JsonProcessingException {

        film film = new film();
       BeanUtils.copyProperties(aboutSo,film);
        film= about.GetFilmByTitleType(film);
        return Result.normal(film,null);
    }
    @PostMapping("/GetFilmFileByTitleType")
    private Result GetFilmFileByTitleType(aboutSo aboutSo) throws JsonProcessingException, InterruptedException {
        film film = new film();
        BeanUtils.copyProperties(aboutSo,film);
        film= about.GetFilmFileByTitleType(film);

        return Result.normal(film,"返回给前端一部film的文件信息");
    }
    @GetMapping({"/downFilm","/downAll"})
    private void downFilm(aboutSo aboutSo) throws IOException {
        request.setAttribute("aboutSo",aboutSo);
        if (aboutSo.getVideo() != null) {
            about.downFilm(aboutSo.getVideo());
        }else {
            about.downAll(aboutSo.getTitle(),aboutSo.getType());
        }
    }
    @GetMapping("/UpdateFolder")
    private Result UpdateFolder(aboutSo aboutSo) throws JsonProcessingException {
        Map<String, String> userMap = utils.GetUserByCookie(request.getCookies());

        Boolean updateFolder = about.UpdateFolder(userMap, aboutSo);
        return  Result.normal(updateFolder,null);
    }
    @PostMapping("/selectFilmFolder")
    private Result selectFilmFolder(aboutSo aboutSo) throws JsonProcessingException {
        Map<String, String> userMap = utils.GetUserByCookie(request.getCookies());
        Boolean folder = about.selectFilmFolder(userMap, aboutSo);

        return Result.normal(folder,null);
    }
}
